package com.octopus.yangj.customized.controller;

import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import com.octopus.kernal.controller.AbstractValidator;
import com.octopus.yangj.generated.model.EventCategoryStruct;

@Component
public class CustomizedEventCategoryValidator extends AbstractValidator{
	
	
    @Override
    public void validate(Object o, Errors errors) {
    	EventCategoryStruct entity = ((EventCategoryStruct) o);
    	if(entity.getLevel() != null && entity.getLevel() != 0){
	        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentId", "error.common.field.empty", new Object[] {messageSource.getMessage("label.event_category.field.parent", new Object[] { }, LocaleContextHolder.getLocale())}, "Please specify a parent");
    	}
    }

}
